package actions;

import java.awt.event.ActionEvent;

import javax.swing.JOptionPane;

import awesomeDocumentIO.AwesomeDocumentExporter;

import dialogs.NewDocumentTypeDialog;
import document.AwesomeDocument;

/**
 * This class is responsible for displaying the visual tools used to create a new document type.
 * @author Brittin
 *
 */
public class CreateDocumentTypeAction extends AwesomeMenuAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public CreateDocumentTypeAction(String name, String desc) {
		super(name, desc);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// Open the Create New Document Dialog
		NewDocumentTypeDialog dialog = new NewDocumentTypeDialog(this.getParentFrame(arg0));
		dialog.setVisible(true);
		
		// Get the entered user information and save it
		String[] info = dialog.getValidatedText();
		if (info == null)
			return;
		
		
		AwesomeDocument doc = new AwesomeDocument(info[1], info[0]);
		if (AwesomeDocumentExporter.exportDocumentType(doc))
			JOptionPane.showMessageDialog(null, "Your document type was succeffully created.");
		else
			JOptionPane.showMessageDialog(null, "There was a problem creating your document.");

	}

}
